import java.util.Scanner;
public class GuessNumber {
    public static void main(String[] args) {
        //生成一个1-100之间的答案数字
        System.out.println("欢迎来到猜数字！");
        while (true) {
            int answer = (int) (Math.random() * 100 + 1);
            //接收玩家输入的数字
            Scanner scan = new Scanner(System.in);
            int chance = 7;
            while (chance > 0) {
                System.out.println("请输入一个1-100之间的整数，包含1和100,你还有" + chance + "次机会");
                int guess = scan.nextInt();
                //比较一次给出反馈
                if (guess > answer) {
                    System.out.println("大了");
                } else if (guess < answer) {
                    System.out.println("小了");
                } else {
                    System.out.println("猜对了");
                    break;
                }
                chance = chance - 1;
            }
            System.out.println("再玩一次吗（y/n）");
            String again = scan.next();
            if (!again.equalsIgnoreCase("y")) {
                break;
            }
        }
    }
}